import { machineCategoryList, getBinMachine, slitRestart } from '@/api/setting'
export default {
  data () {
    return {
      machineTypeList: [],
      modalShow: false, // 批量操作对话框显示
      dataTree: [], // 树
      checkdList: [], // 已选的数组
      setModalStatus: false, // 二次modal弹框状态
      pageObj: {
        total: 0,
        pageIndex: 1,
        pageSize: 10
      },
      historyObj: {
        total: 0,
        pageIndex: 1,
        pageSize: 10
      },
      titleObj: {
        mainTitle: '批量设置',
        leftTitle: '可选机台',
        rightTitle: '已选机台',
        searchTitle: '选择机台',
        bottomTitle: '下一步'
      }
    }
  },
  methods: {
    // 取消二次弹框
    cancelModal () {
      this.setModalStatus = false
      this.dataTree = []
      this.checkdList = []
    },
    // 取消一次弹框
    selctshopCancel () {
      this.modalShow = false
      this.dataTree = []
      this.checkdList = []
    },
    // 上一步
    skipPrevious () {
      this.setModalStatus = false
      this.modalShow = true
      this.allSet()
    },
    // 点击批量
    allSet () {
      // machineInstanceList({
      //   shopId: this.$route.query.shopId
      // }).then(res => {
      //   this.modalShow = true
      //   if (res.data.status === 200) {
      //     this.formatShopProjects(res.data.data || [])
      //   } else {
      //     this.$Message.error(`${res.data.error}`)
      //   }
      // })
      // slitAnimationList({
      //   shopId: this.$route.query.shopId,
      //   merchantId: this.$store.state.user.merchantId,
      //   shopName: this.$route.query.shopName,
      //   machineCategoryId: '',
      //   machineName: '',
      //   state: '',
      //   offset: 0,
      //   limit: 10000
      // }).then(res => {
      //   this.modalShow = true
      //   if (res.data.status === 200) {
      //     this.formatShopProjects(res.data.data || [])
      //   } else {
      //     this.$Message.error(`${res.data.error}`)
      //   }
      // })
      getBinMachine({
        shopId: this.$route.query.shopId,
        merchantId: this.$store.state.user.merchantId
      }).then(res => {
        this.modalShow = true
        if (res.data.status === 200) {
          this.formatShopProjects(res.data.data || [])
        } else {
          this.$Message.error(`${res.data.error}`)
        }
      })
    },
    // 格式化组件key
    formatShopProjects (projects) {
      // this.dataTree = projects.map(item => {
      //   item.orgName = item.name
      //   item.id = item.machineInstanceId
      //   item.orgType = 1
      //   item.childList = []
      //   return item
      // })
      this.dataTree = projects.map(item => {
        item.orgName = item.machineInstanceName
        item.id = item.machineInstanceId
        item.orgType = 1
        item.childList = []
        return item
      })
    },
    // 重启
    reStart (row) {
      slitRestart({
        slotId: row.machineInstanceSoltId
      }).then(res => {
        if (res.data.status === 200) {
          this.$Message.success('重启成功！')
        } else {
          this.$Message.error(`${res.data.error}`)
        }
      })
    },
    // 获取机台分类
    getMachineList () {
      machineCategoryList({
        merchantId: this.$store.state.user.merchantId
      }).then(res => {
        const result = res.data || {}
        if (result.status === 200) {
          this.machineTypeList = result.data || []
        } else {
          this.$Message.error(`${result.error}`)
        }
      })
    },
    // 重置
    reset () {
      this.machineName = ''
      this.machineType = ''
      this.operationStatus = ''
      this.pageObj.pageIndex = 1
      this.pageObj.pageSize = 10
      this.getData()
    }
  }
}
